# 循环语句 while for


# 打印1~10的整数
num = 1
while num <= 10:
    print(num)
    num = num + 1

'''
num = 1  循环变量的初始值
while num <= 10:  循环的判定条件
    print(num)
    num = num + 1  循环变量的更新语句
'''


# 计算1-100的和

sum = 0
num = 1

while num <= 100:
    sum += num
    num += 1
print(sum)


# 计算5的阶乘

result = 1
num = 1
while num <= 5:
    result *= num
    num += 1
print(result)


# 求 1！ +2！ +3！ +4！+5！

sum = 0
# sum表示最终结果result=1
num = 1
while num <= 5:
    result *= num
    num += 1
print(result)

num = 1
while num <= 5:
    # 先计算出num!是多少，往sum上进行累加
    factorResult = 1
    i = 1
    while i <= num:
        factorResult *= i
        i += 1
    sum += factorResult
    num += 1

print(sum)


